<template>
  <div class="statisticalanalysis-data">
    <el-card :body-style="{ padding: '0px' }">
      <div slot="header">
        <tools-btn
          :toolsData="toolsData"
          @addData="addData"
          @refresh="refresh"
          @search="search"
          @fieldSet="fieldSet"
          @hasOperation="hasOperation"
        />
      </div>
      <div id="myChart" :style="{width: '500px', height: '500px', marginTop: '20px', marginLeft: '20px',}"></div>
    </el-card>
  </div>
</template>
<script>
import ToolsBtn from "../../components/Tools/ToolsBtn";
import echarts from "echarts";
require('echarts/lib/chart/pie');
require('echarts/lib/component/title');
require('echarts/lib/component/tooltip');
require('echarts/lib/component/legend');
require("echarts/lib/component/legendScroll");
export default {
  name: "StatisticalAnalysis",
  components: {
    ToolsBtn
  },
  data () {
    return {
      toolsData: {
        title: '统计分析显示',
        oBtnShow: [
          { btn0: false }, // 新增按钮
          { btn1: false }, // 刷新按钮
          { btn2: false }, // 搜索按钮
          { btn3: false }, // 设置按钮
          { btn4: false } // 导出Excel按钮
        ]
      },
      repastCount: ''
    }
  },
  created () {
    this.drawLine();
  },
  methods: {
    drawLine(){
      this.$api.BASICDISPLAY.basicData()
      .then(res => {
       this.repastCount = res.data.repastCount
       let myChart = echarts.init(document.getElementById('myChart'))
        myChart.setOption({
          title : {},
          tooltip : {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c}"
          },
          legend: {
            orient: 'vertical',
            left: 'left',
            data: ['餐饮企业数量','清洗企业数量','在线设备数量','待处理问题数']
          },
          series : [
            {
              name: '访问来源',
              type: 'pie',
              radius : '55%',
              center: ['50%', '60%'], 
              data:[
                {value:res.data.repastCount, name:'餐饮企业数量'},
                {value:res.data.cleanerCount, name:'清洗企业数量'},
                {value:res.data.onlineCount, name:'在线设备数量'},
                {value:res.data.pendingCount, name:'待处理问题数'}
              ],
              itemStyle: {
                emphasis: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            }
          ]
        });
      })
      .catch(() => {
        this.$message({
          message:"暂无数据",
          type: 'error'
        }); 
      })
    },
    // 新增数据
    addData(){

    },
    // 刷新数据
    refresh(){

    },
    // 搜索
    search(){

    },
    // 设置字段
    fieldSet(){

    },
    // 隐藏表格操作列
    hasOperation(){
      this.table.hasOperation = !this.table.hasOperation;
    }
  }
}
</script>
<style lang="scss" scoped>

</style>